package com.shuo.dsa.leetcode;

import com.shuo.dsa.model.ListNode;

/**
 * 判断是否有环:
 *      思路: 快慢指针
 */
public class IsCircleList {
    public boolean hasCycle(ListNode head) {
        if (head == null) return false;
        ListNode slow = head;
        ListNode fast = head;
        while (fast.next != null && fast.next.next != null) {
            slow = slow.next;
            fast = fast.next.next;
            if (slow == fast) return true;
        }
        return false;
    }
}
